package se.webbzon.boltzmann.editor.component.battlepropertylist;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JList;
import javax.swing.ListCellRenderer;

import se.webbzon.boltzmann.battle.property.BattlePropertyFactory;
import se.webbzon.boltzmann.editor.list.EditorListCell;

public class BPFListCell extends EditorListCell implements ListCellRenderer<BattlePropertyFactory> {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = 3416436587159191410L;
	
	// The battle property factory associated with this list cell
	private BattlePropertyFactory factory;
	
	/*============================================================
	Constructors
	============================================================*/

	public BPFListCell(Dimension d) {
		super(d);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setFont(getFont());
		g.drawImage(factory.getTextureSample().getImage(), 0, 0, 64, 64, this);
		g.drawString(factory.getName(), 80, 32);
	}

	@Override public Component getListCellRendererComponent(
			JList<? extends BattlePropertyFactory> list, 
			BattlePropertyFactory factory, int index,
			boolean isSelected, boolean cellHasFocus) {
		setSelected(isSelected);
		this.factory = factory;
		return this;
	}

}
